package com.znf4.controller.trade;
/*package com.znf4.platform.controller.trade;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.znf4.platform.common.core.config.SystemConfig;
import com.znf4.platform.common.core.dwz.DWZ;
import com.znf4.platform.common.core.dwz.DwzAjax;
import com.znf4.platform.common.core.page.PageBean;
import com.znf4.platform.common.core.page.PageParam;
import com.znf4.platform.common.core.utils.DownloadUtil;
import com.znf4.platform.common.core.utils.FtpUtil;
import com.znf4.platform.common.core.utils.QRCodeUtil;
import com.znf4.platform.common.core.utils.SFTPUtil;
import com.znf4.platform.common.core.utils.StringUtil;
import com.znf4.platform.trade.entity.tq.TQInfo;
import com.znf4.platform.trade.enums.TQStatusEnum;
import com.znf4.platform.trade.service.RpTQManagerService;
import com.znf4.platform.user.service.RpUserInfoService;

*//**
 * 类功能说明：台签、电子签信息管理
 *//*
@Controller
@RequestMapping("/tqInfo")
public class TQInfoController {

	// private static final Log LOG = LogFactory.getLog(TQInfoController.class);

	// 二维码内容
	// public static final String QRCODE_CONTENT =
	// SystemConfig.QRCODE_CONTENT.trim();
	// 二维码LOGO路径
	// public static final String QRCODE_LOGO_PATH =
	// SystemConfig.QRCODE_LOGO_PATH.trim();
	// 二维码图片格式
	// public static final String QRCODE_FORMAT =
	// SystemConfig.QRCODE_FORMAT.trim();
	// FTP根目录
	// public static final String FTP_PROJECT = SystemConfig.FTP_PROJECT.trim();

	*//**
	 * 注入台签管理接口
	 *//*
	private RpTQManagerService rpTQManagerService;

	public RpTQManagerService getRpTQManagerService() {
		return rpTQManagerService;
	}

	@Autowired
	public void setRpTQManagerService(RpTQManagerService rpTQManagerService) {
		this.rpTQManagerService = rpTQManagerService;
	}

	*//**
	 * 注入用户信息接口
	 *//*
	private RpUserInfoService rpUserInfoService;

	public RpUserInfoService getRpUserInfoService() {
		return rpUserInfoService;
	}

	@Autowired
	public void setRpUserInfoService(RpUserInfoService rpUserInfoService) {
		this.rpUserInfoService = rpUserInfoService;
	}

	*//**
	 * 函数功能说明 ：导出已分派台签
	 * 参数：@param response 参数：@param agentNo 参数：@return <br/>
	 * return：String <br/>
	 * 
	 * @throws Exception
	 *//*
	@RequiresPermissions("tq:tqInfo:export")
	@RequestMapping(value = "/exportTq", method = RequestMethod.GET)
	public String exportTq(HttpServletResponse response, @RequestParam("agentNo") String agentNo) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("agentNo", agentNo);
		paramMap.put("status", TQStatusEnum.ALLOTTED.toString());
		List<TQInfo> tqList = rpTQManagerService.getList(paramMap);
		if (!StringUtil.isEmpty(tqList)) {
			List<String> imgUrls = new ArrayList<String>();
			for (int i = 0; i < tqList.size(); i++) {
				TQInfo tq = tqList.get(i);
				imgUrls.add(tq.getImgUrl());
			}
			DownloadUtil.zipDownload(response, agentNo, imgUrls);
		}
		return null;
	}

	*//**
	 * 函数功能说明 ：修改台签状态
	 * 参数：@param id 参数：@param status 参数：@param model 参数：@return <br/>
	 * return：String <br/>
	 *//*
	@RequiresPermissions("tq:tqInfo:edit")
	@RequestMapping(value = "/status", method = RequestMethod.POST)
	public String status(@RequestParam("id") String id, @RequestParam("status") String status, DwzAjax dwz, Model model) {
		if (StringUtil.isEmpty(id)) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("台签id不能为空");
		} else {
			TQInfo tq = rpTQManagerService.getDataById(id);
			tq.setStatus(status);
			rpTQManagerService.updateData(tq);
			dwz.setStatusCode(DWZ.SUCCESS);
			dwz.setMessage(DWZ.SUCCESS_MSG);
		}
		model.addAttribute("dwz", dwz);
		return DWZ.AJAX_DONE;
	}

	*//**
	 * 函数功能说明 ： 查看台签详情
	 * 参数：@param id 参数：@param model 参数：@return <br/>
	 * return：String <br/>
	 *//*
	@RequiresPermissions("tq:tqInfo:view")
	@RequestMapping(value = "/viewUI", method = RequestMethod.GET)
	public String viewUI(@RequestParam("id") String id, Model model) {
		TQInfo tq = rpTQManagerService.getDataById(id);
		model.addAttribute("bean", tq);
		return "tqInfo/view";
	}

	*//**
	 * 函数功能说明 ：批量分派台签给代理商
	 * 参数：@param pageParam 参数：@param dwz 参数：@param model 参数：@param fpCount 参数：@return
	 *
	 * return：String <br/>
	 * 
	 * @throws Exception
	 *//*
	@RequiresPermissions("tq:tqInfo:allotted")
	@RequestMapping(value = "/allotted", method = { RequestMethod.POST })
	public String allotted(HttpServletRequest request, DwzAjax dwz, Model model, @RequestParam("fpCount") String fpCount, @RequestParam("unAllotCount") String unAllotCount) throws Exception {
		if (StringUtil.isEmpty(fpCount)) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("请输入分派台签数");
		} else if (Integer.valueOf(fpCount).intValue() <= 0) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("输入分派台签数必须大于0");
		} else if (Integer.valueOf(fpCount).intValue() > Integer.valueOf(unAllotCount).intValue()) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("最多分派台签" + unAllotCount + "张");
		} else {
			// 未被分派台签
			Map<String, Object> paramMap = new HashMap<String, Object>();
			int count = Integer.valueOf(fpCount).intValue();
			paramMap.put("count", count);
			paramMap.put("status", TQStatusEnum.UN_ALLOT.toString());
			List<TQInfo> tqList = rpTQManagerService.getList(paramMap);
			if (tqList.size() <= 0) {
				dwz.setStatusCode(DWZ.ERROR);
				dwz.setMessage("没有可分派的台签");
			} else {
				String agentNo = request.getParameter("agent.userNo");
				String agentName = request.getParameter("agent.userName");
				for (int i = 0; i < tqList.size(); i++) {
					TQInfo tq = tqList.get(i);
					tq.setStatus(TQStatusEnum.ALLOTTED.toString());
					// 没选择代理商则为分派给平台
					if (StringUtil.isEmpty(agentNo) && StringUtil.isEmpty(agentName)) {
						tq.setAgentNo("0");
						tq.setAgentName("RC支付平台商");
					} else {
						tq.setAgentNo(agentNo);
						tq.setAgentName(agentName);
					}
					if (StringUtil.isEmpty(tq.getUrl())) {
						String content = SystemConfig.QRCODE_CONTENT.replace("{TQNO}", tq.getTqNo());
						tq.setUrl(content);
						// 生成二维码图片
						String logoPath = request.getSession().getServletContext().getRealPath(SystemConfig.QRCODE_LOGO_PATH);
						InputStream inputStream = QRCodeUtil.getInputStream(content, logoPath, true);
						String fileName = tq.getTqNo() + "." + SystemConfig.QRCODE_FORMAT;
//						String destPath = FtpUtil.upload(SystemConfig.FTP_PROJECT, inputStream, fileName, "tqInfo", "img");
						String destPath = SFTPUtil.upload(SystemConfig.FTP_PROJECT, inputStream, fileName, "tqInfo", "img");
						tq.setImgUrl(destPath);
					}
					tq.setLevel("1");
					rpTQManagerService.updateData(tq);
				}
				dwz.setStatusCode(DWZ.SUCCESS);
				dwz.setMessage("台签分派成功");
			}
		}
		model.addAttribute("dwz", dwz);
		return DWZ.AJAX_DONE;
	}

	*//**
	 * 函数功能说明 ：进入分派台签页面
	 * 参数：@param model 参数：@param tqInfo 参数：@return <br/>
	 * return：String <br/>
	 *//*
	@RequiresPermissions("tq:tqInfo:allotted")
	@RequestMapping(value = "/allottedUI", method = { RequestMethod.GET })
	public String allottedUI(Model model, TQInfo tqInfo) {
		// 统计未被分派数UN_ALLOT
		tqInfo.setStatus(TQStatusEnum.UN_ALLOT.toString());
		Long unAllotCount = rpTQManagerService.getCountByColumn(tqInfo);
		model.addAttribute("unAllotCount", unAllotCount);
		return "tqInfo/allotted";
	}

	*//**
	 * 函数功能说明 ：批量保存台签信息
	 * 参数：@param dwz 参数：@param model 参数：@param tqInfo 参数：@return <br/>
	 * return：String <br/>
	 *//*
	@RequiresPermissions("tq:tqInfo:add")
	@RequestMapping(value = "/add", method = { RequestMethod.POST })
	public String add(HttpServletRequest request, DwzAjax dwz, Model model, @RequestParam("tqCount") String tqCount) throws Exception {
		if (StringUtil.isEmpty(tqCount)) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("请输入生成台签数");
		} else if (Integer.valueOf(tqCount).intValue() <= 0) {
			dwz.setStatusCode(DWZ.ERROR);
			dwz.setMessage("输入生成台签数大于0");
		} else {
			List<TQInfo> tqList = new ArrayList<TQInfo>();
			Long count = Long.valueOf(tqCount).longValue();
			for (Long i = 0L; i < count; i++) {
				TQInfo tqInfo = new TQInfo();
				tqInfo.setCreateTime(new Date());
				tqInfo.setStatus(TQStatusEnum.UN_ALLOT.toString());
				tqInfo.setTqNo(rpTQManagerService.buildTqNo());

				String content = SystemConfig.QRCODE_CONTENT.replace("{TQNO}", tqInfo.getTqNo());
				tqInfo.setUrl(content);
				// 生成二维码图片
				String logoPath = request.getSession().getServletContext().getRealPath(SystemConfig.QRCODE_LOGO_PATH);
				InputStream inputStream = QRCodeUtil.getInputStream(content, logoPath, true);
				String fileName = tqInfo.getTqNo() + "." + SystemConfig.QRCODE_FORMAT;
//				String destPath = FtpUtil.upload(SystemConfig.FTP_PROJECT, inputStream, fileName, "tqInfo", "img");
				String destPath = SFTPUtil.upload(SystemConfig.SFTP_PROJECT, inputStream, fileName, "tqInfo", "img");
				tqInfo.setImgUrl(destPath);
				tqList.add(tqInfo);
			}
			rpTQManagerService.batchInsert(tqList);
			dwz.setStatusCode(DWZ.SUCCESS);
			dwz.setMessage(DWZ.SUCCESS_MSG);
		}
		model.addAttribute("dwz", dwz);
		return DWZ.AJAX_DONE;
	}

	*//**
	 * 函数功能说明 ： 分页列表获取台签信息
	 * 参数：@param request 参数：@param pageParam 参数：@param tqInfo 参数：@param model
	 * 参数：@return <br/>
	 * return：String <br/>
	 *//*
	@RequiresPermissions("tq:tqInfo:view")
	@RequestMapping(value = "/list", method = { RequestMethod.POST, RequestMethod.GET })
	public String list(HttpServletRequest request, PageParam pageParam, TQInfo tqInfo, Model model) {
		String merchantNo = request.getParameter("merchant.userNo");
		String agentNo = request.getParameter("agent.userNo");
		if (!StringUtil.isEmpty(merchantNo)) {
			tqInfo.setMerchantNo(merchantNo);
		}
		if (!StringUtil.isEmpty(agentNo)) {
			tqInfo.setAgentNo(agentNo);
		}
		PageBean pageBean = rpTQManagerService.listPage(pageParam, tqInfo);
		model.addAttribute("pageBean", pageBean);
		model.addAttribute("pageParam", pageParam);
		model.addAttribute("merchantNo", merchantNo);
		model.addAttribute("agentNo", agentNo);
		Long unAllotCount = 0L;
		Long allottedCount = 0L;
		Long bindingCount = 0L;
		Long cancelCount = 0L;
		if (StringUtil.isEmpty(tqInfo.getStatus())) {
			// 统计未被分派数UN_ALLOT
			tqInfo.setStatus(TQStatusEnum.UN_ALLOT.toString());
			unAllotCount = rpTQManagerService.getCountByColumn(tqInfo);
			// 统计已被分派数ALLOTTED
			tqInfo.setStatus(TQStatusEnum.ALLOTTED.toString());
			allottedCount = rpTQManagerService.getCountByColumn(tqInfo);
			// 统计已绑定数IS_BINDING
			tqInfo.setStatus(TQStatusEnum.IS_BINDING.toString());
			bindingCount = rpTQManagerService.getCountByColumn(tqInfo);
			// 统计已取消数CANCEL
			tqInfo.setStatus(TQStatusEnum.CANCEL.toString());
			cancelCount = rpTQManagerService.getCountByColumn(tqInfo);
		} else {
			unAllotCount = rpTQManagerService.getCountByColumn(tqInfo);
			allottedCount = rpTQManagerService.getCountByColumn(tqInfo);
			bindingCount = rpTQManagerService.getCountByColumn(tqInfo);
			cancelCount = rpTQManagerService.getCountByColumn(tqInfo);
		}
		model.addAttribute("unAllotCount", unAllotCount);
		model.addAttribute("allottedCount", allottedCount);
		model.addAttribute("bindingCount", bindingCount);
		model.addAttribute("cancelCount", cancelCount);
		return "tqInfo/list";
	}

}
*/